<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('托管服务器列表')" />
</head>
<body class="gray-bg" style="background-color: #ffffff;">
<div class="container-div" style="padding: 5px 20px;">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label style="width: 120px;">托管服务器名称：</label>
                                <input type="text" name="serName"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="scriptInstallUri()">
                     点击复制nginx安装脚本
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="SSL:service:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="SSL:service:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <!--<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="SSL:service:export">
                    <i class="fa fa-download"></i> 导出
                </a>-->
            </div>
            <div class="col-sm-12 select-table table-bordered">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('SSL:service:edit')}]];
        var removeFlag = [[${@permission.hasPermi('SSL:service:remove')}]];
        var prefix = ctx + "SSL/service";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "托管服务器",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '托管Id',
                    visible: false
                },
                {
                    field: 'serIp',
                    title: '服务器IP',
                    formatter:function (value, row, index){
                        return "<a style='color: #1C84C6; font-weight: bold;' onclick='openDomainListPage(\""+row.serIp+"\", \""+row.id+"\")'>"+value+"</a>";
                    }
                },
                {
                    field: 'serName',
                    title: '服务器名称'
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    field: 'lastCheckDate',
                    title: '最后连接系统时间',
                    formatter:function (value, row, index){
                        if(row.status){
                            if(row.status === 'Y'){
                                return "<span style='color: #12B980; font-weight: bold;'>"+value+"</span>";
                            }else{
                                return "<span style='color: red; font-weight: bold;'>"+value+"</span>"
                            }
                        }else{
                            return "<span style='color: red; font-weight: bold;'>"+value+"</span>"
                        }
                    }
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter:function (value, row, index){
                        if(value){
                            if(value === 'Y'){
                                return "<span style='color: #12B980; font-weight: bold;'><i class='fa fa-check'></i>&nbsp;正常</span>";
                            }else{
                                return "<span style='color: red; font-weight: bold;'><i class='fa fa-close'></i>&nbsp;异常</span>"
                            }
                        }else{
                            return "<span style='color: red; font-weight: bold;'><i class='fa fa-close'></i>&nbsp;异常</span>"
                        }
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="openDomainListPage(\'' + row.serIp + '\',\'' + row.id + '\')"><i class="fa fa-navicon"></i>证书列表</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function copyToClipboard(text) {
            var textarea = document.createElement('textarea');
            textarea.style.position = 'fixed';
            textarea.style.opacity = 0;
            textarea.value = text;
            document.body.appendChild(textarea);
            textarea.select();
            document.execCommand('copy');
            document.body.removeChild(textarea);
            $.modal.msgSuccess("复制成功！");
        }

        function scriptInstallUri(){
            $.operate.get(prefix + "/scriptInstallUri", function (res){
                if(res.code === 0){
                    if(res.data){
                        copyToClipboard(res.data)
                    }else{
                        $.modal.msgWarning("不存在安装脚本！");
                    }
                }
            });
        }

        function openDomainListPage(serIp, id){
            window.parent.openDomainListPage(serIp, id)
        }
    </script>
</body>
</html>
